package edu.fdzc.shop.controller;


import edu.fdzc.shop.dto.ReviewDto;
import edu.fdzc.shop.service.ReviewService;
import edu.fdzc.shop.utils.JwtUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * DESCRIPTION:
 * 评论相关接口
 */
@RestController
@RequestMapping("/api/review")
public class ReviewController {

    //private static final Logger logger = LoggerFactory.getLogger(ProductController.class);

    @Resource
    private ReviewService reviewService;

    /**
     * 添加评论
     * @param reviewDto
     * @param token
     * @return
     */
    @PostMapping("/add")
    public boolean add(@RequestBody ReviewDto reviewDto, @RequestHeader String token) {
        //logger.debug("添加评论请求参数，reviewDto:{}, token:{}", reviewDto, token);
        return reviewService.saveReview(reviewDto, JwtUtils.getUserId(token));
    }

    /**
     * 查看评论列表
     * @param productId
     * @return
     */
    @GetMapping("/list/{productId}")
    public List<ReviewDto> list(@PathVariable("productId") String productId) {
        //logger.debug("查看评论列表请求参数，productId:{}", productId);
        return reviewService.list(productId);
    }

    /**
     * 删除评论
     * @param reviewId
     * @return
     */
    @DeleteMapping("/delete/{reviewId}")
    public Boolean delete(@PathVariable("reviewId") String reviewId) {
        //logger.debug("删除评论请求参数，reviewId:{}", reviewId);
        return reviewService.delete(reviewId);
    }

}
